/**
 * By Alpha
 * Author: alixez <alixe.z@foxmail.com>
 * Date: 2017/10/27
 */
import modelExtend from 'dva-model-extend';

const Model = {
  reducers: {
    updateState (state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};

const pageModel = modelExtend(Model, {
  state: {
    list: [],
    pagination: {
      showSizeChanger: true,
      showQuickJumper: true,
      showTotal: total => `总计 ${total} 条数据`,
      current: 1,
      total: 0,
      pageSize: 10,
    },
  },

  reducers: {
    loadSuccess (state, { payload }) {
      const { list, pagination } = payload;
      return {
        ...state,
        list,
        pagination: {
          ...state.pagination,
          ...pagination,
        },
      };
    },
  },
});

export {
  Model,
  pageModel,
};
